package com.robert.vesta.service.factory;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int x = m*n;
        int[][] arr = new int[n][m];
        for(int i = 0; i < x; i++) {
            arr[i/n][i%m] = scanner.nextInt();
        }
        int count = m + m/2;
        int[] reslut = new int[count];
        int position = 0;
        for(int i = 0; i < n; i++) {
            int j = 0;
            if(i % 2 == 0) {
               j = 1;
            } else {
                j = 0;
            }
            for(; j < m; j+=2) {
                reslut[position++] = arr[i][j];
            }
        }
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for(int i = 0; i < count; i++) {
            if(null == map.get(reslut[i])) {
                map.put(reslut[i],1);
            } else {
                Integer integer = map.get(reslut[i]);
                integer++;
                map.put(reslut[i],integer);
            }
        }
        Collection<Integer> values = map.values();
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.addAll(values);
        Collections.sort(list);
        Integer integer = list.get(list.size() - 1);

        System.out.println(m+m/2 - integer);
    }
}
